package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.dao.WmsrRailwayPlatformMapper;
import com.jy.wms.pojo.WmsLibrarypositiongroup;
import com.jy.wms.pojo.WmsrRailwayPlatform;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @ClassName: WmsrRailwayPlatformService.java
* @Description: TODO(这里用一句话描述这个类的作用)
* @Author ln
* @Date Tue Oct 10 10:08:00 CST 2017
*/

@Service
public class WmsrRailwayPlatformService extends BaseService<WmsrRailwayPlatformMapper,WmsrRailwayPlatform> {

 /**
 * 插入一条记录
 * @param entity 实体对象
 * @return int
 */
 @BaseServiceDescribe(moduleName = "月台添加",btnName = "月台添加")
public void baseInsert( WmsrRailwayPlatform entity)throws SucessException,ServiceException {
        int getCounts=dao.getcount(entity.getYtmc(),entity.getSshzid(),null);//查询月台名称
        if (getCounts==0){
        entity.setId(UUIDUtils.uuid());
        int i=dao.baseInsert(entity);
        if (i>0){
            throw new SucessException("月台新增成功");
        }else {
            throw new ServiceException("月台新增失败");
        }
        }else {
            throw new ServiceException("月台名称不可重复新增");
        }

}

/**
* 插入一条记录（匹配有值的字段）
* @param entity 实体对象
* @param database 数据库名称
* @return int
*/
public Integer baseInsertSelective(WmsrRailwayPlatform entity, String database ){
     return dao.baseInsertSelective( entity,database );
}

/**
* 删除（根据主键ID删除）
* @param id 主键
* @param database 数据库名称
* @return int
*/
public Integer baseDeleteByPrimaryKey(String id, String database ){
     return dao.baseDeleteByPrimaryKey( id,database );
}

/**
* 删除（根据ID 批量删除）
* @param idList 主键ID列表
* @return int
*/
@BaseServiceDescribe(moduleName = "删除",btnName = "根据id批量删除")
public void  baseDeleteBathPrimaryKeys( List<String> idList) throws SucessException,ServiceException {
        int i=dao.baseDeleteBathPrimaryKeys(idList);
        if (i>0){
            throw new SucessException("月台删除成功");
        }else {
            throw new ServiceException("月台删除失败");
        }


}

/**
* 分页查询
* @param entity 实体
* @return Page<WmsrRailwayPlatform>
*/
@BaseServiceDescribe(moduleName = "月台",btnName = "分页查询")
public Page<WmsrRailwayPlatform> baseSelectPage(WmsrRailwayPlatform entity) throws Exception {
    Page<WmsrRailwayPlatform> list=null;
    try {
        PageHelper.startPage(entity.getPage(),entity.getRows());
        list=(Page<WmsrRailwayPlatform>)dao.baseSelectPage(entity);
        return list;
    }catch (Exception e){
        throw new ServiceException("月台分页查询失败",e);
    }
}

    /**
     * 查询货主
     * @param mc
     * @return
     */
 /*  @BaseServiceDescribe(moduleName = "月台",btnName = "模糊查询货主")
    public List<WmsOwner> hzSearch(String mc){
        if (mc!=null && mc.equals("")){
        }else{
            PageHelper.startPage(1,20);
        }
        return dao.hzSearch(mc);
    }*/



/**
* 查询（根据ID 批量查询）
* @param idList 主键ID列表
* @param database 数据库名称
* @return list
*/
public Integer baseSelectBathPrimaryKeys(List<WmsrRailwayPlatform> idList, String database ){
     return dao.baseSelectBathPrimaryKeys( idList,database );
}



/**
*修改（根据主键ID修改）
* @param entity 主键ID列表
* @param database 数据库名称
* @return int
*/
public Integer baseUpdateByPrimaryKey(WmsrRailwayPlatform entity, String database ){
     return dao.baseUpdateByPrimaryKey( entity,database );
}
    /**
     * 库位组分页查询
     */
    @BaseServiceDescribe(moduleName = "库位组",btnName = "库位组查询")
    public Page<WmsLibrarypositiongroup> kwzSelectPage(@Param("WmsLibrarypositiongroup") WmsLibrarypositiongroup entity) throws Exception {
        Page<WmsLibrarypositiongroup> list=null;
        try {
            PageHelper.startPage(entity.getPage(),entity.getRows());
            list=(Page<WmsLibrarypositiongroup>)dao.kwzSelectPage(entity);
            return list;
        }catch (Exception e){
            throw new ServiceException("库位组查询失败",e);
        }
    }

    /**
     * 根据id查询月台（根据主键ID查询）
     * @param id 主键ID
     * @return WmsrRailwayPlatform
     */
        @BaseServiceDescribe(moduleName = "根据id查询月台",btnName = "根据id查询月台")
      public WmsrRailwayPlatform baseSelectByPrimaryKey(String id) throws Exception {
          WmsrRailwayPlatform wrf=null;
        try{
            wrf= dao.baseSelectByPrimaryKey(id);
            return wrf;
        }catch (Exception e){
            throw new ServiceException("月台查询失败",e);
        }
    }

    /**
     * 编辑月台（匹配有值的字段）
     * @param entity 主键ID列表
     * @return int
     */
    @BaseServiceDescribe(moduleName = "编辑月台",btnName = "编辑月台")
    public void baseUpdateByPrimaryKeySelective( WmsrRailwayPlatform entity )throws SucessException,ServiceException {
            int getCounts=dao.getcount(entity.getYtmc(),entity.getSshzid(),entity.getId());//查询月台名称
           if (getCounts==0){
               if (entity.getFhbj().equals("0")){
                   entity.setDykwzid("");
               }
            int i=dao.baseUpdateByPrimaryKeySelective(entity);
            if (i>0){
                throw new SucessException("月台编辑成功");
            }else {
                throw new ServiceException("月台编辑失败");
            }
        }else {
            throw new ServiceException("相同货主下的月台名称不可重复");
        }

    }
}
